package com.eling.elcms.travel.service.impl;

import com.eling.elcms.core.util.PropertyUtils;
import com.eling.elcms.travel.model.RoomRegister;
import com.eling.elcms.travel.model.RoomTypePrice;
import com.eling.elcms.travel.model.TravelContract;
import com.eling.elcms.travel.model.view.SettlementsResult;
import com.eling.elcms.travel.model.view.SumRoomPrice;
import com.eling.elcms.travel.service.IRoomTypePriceManager;
import com.eling.elcms.travel.service.ISettlementsRule;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 5%床位费补贴规则
 * @author Lina
 * 规则 ：给予9.5折的床位费折扣（减免5%的床位费）
 */
@Service
public class FiveBedSubsidyServiceImpl implements ISettlementsRule {
	
	@Autowired
	private IRoomTypePriceManager roomPriceM;
	
	private static final Log log = LogFactory.getLog(FiveBedSubsidyServiceImpl.class);

	@Override
	public SettlementsResult calculate(RoomRegister room, TravelContract contract, Date start, Date end) {
		log.debug("FiveBedSubsidyServiceImpl");
		
		SettlementsResult result = new SettlementsResult();

		if (room != null){
			// 获取合同结算时居住期间的房价总和
			RoomTypePrice cond = new RoomTypePrice();
			cond.setRoomType(room.getRoom().getRoomType());
			cond.setSaleDate(start);
			PropertyUtils.setProperty(cond, "saleDateEnd", end);
			SumRoomPrice roomPrice = roomPriceM.querySumRoomPrice(cond);
			
			// 根据房间所属房型的价格计算折扣后的价格（取VIP价）
			result.setMoney(roomPrice.getSumVipPrice() * 0.05);
		}

		return result;
	}
	
}
